#include<iostream>
#include<future>
#include<chrono>
#include<thread>
int add(int a,int b)
{
    std::cout<<"+"<<std::endl;
    return a+b;
}
int main()
{
    //async 返回值为future对象 async(fun,...)  async(policy,fun,...)
    //std::launch::deferred 必须执行到get时才会去调用add---什么时候需要就什么时候去取
    //std::launch::async 内部会创建工作线程，异步的完成任务
    std::cout<<"--------1---------"<<std::endl;
    std::future<int> ret = std::async(std::launch::async,add,10,20);
    std::this_thread::sleep_for(std::chrono::seconds(2));
    std::cout<<"--------2---------"<<std::endl;
    int sum = ret.get();
    std::cout<<"--------3---------"<<std::endl;
    std::cout<<sum<<std::endl;
    return 0;
}